package com.sys.controller;

import com.sys.common.aop.Operation;
import com.sys.common.constant.Constant;
import com.sys.common.util.ResponseDateUtil;
import com.sys.common.util.ResultBuilder;
import com.sys.pojo.Check;
import com.sys.service.CheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ZJF
 * @since 2021-04-01
 */
@Api(tags = {"考核管理"})
@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private CheckService checkService;

    @PostMapping("/listAllCheck")
    @RequiresPermissions("check:list")
    @ApiOperation("获取全部考核信息")
    public ResponseDateUtil getAllCheck(@RequestBody Check check) {
        return ResultBuilder.success(checkService.findListByPage(check));
    }


    @PostMapping("/addCheck")
    @RequiresPermissions("check:add")
    @ApiOperation("添加考核信息")
    @Operation("添加考核信息")
    public ResponseDateUtil addCheck(@RequestBody Check check) {
        if (checkService.add(check) > 0) {
            return ResultBuilder.success(Constant.ADDSUCCESS);
        } else {
            return ResultBuilder.errorInfo(Constant.ADDFAILED);
        }
    }

    @PutMapping("/updCheck")
    @RequiresPermissions("check:upd")
    @ApiOperation("更新考核信息")
    @Operation("更新考核信息")
    public ResponseDateUtil updCheck(@RequestBody Check check) {
        if (checkService.updateData(check) > 0) {
            return ResultBuilder.success(Constant.UPDSUCCESS);
        } else {
            return ResultBuilder.errorInfo(Constant.UPDFAILED);
        }
    }

    @DeleteMapping("/delCheck")
    @RequiresPermissions("check:del")
    @ApiOperation("删除考核信息")
    @Operation("删除考核信息")
    public ResponseDateUtil delCheck(@RequestParam("id") Integer id) {
        if (checkService.delete(id) > 0) {
            return ResultBuilder.success(Constant.DELSUCCESS);
        } else {
            return ResultBuilder.errorInfo(Constant.DELFAILED);
        }
    }

}
